<style lang="less">
  @import 'Teacher.less';
</style>
<template>
  <Form :model="formItem" :label-width="80">
    <input type="hidden" v-model="formItem.id">
    <FormItem label="名称">
      <Input v-model="formItem.name" placeholder="请输入名称">
        <Icon type="ios-person-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem label="密码">
      <Input v-model="formItem.password" placeholder="如果不需要修改密码请留空">
        <Icon type="ios-lock-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <Button type="primary" size="large" class="on-btn" @click="btnSaveClick">确认修改</Button>
  </Form>
</template>

<script>
  import {getTeacher, updateTeacher, getTeacherList,getCurrentTeacher} from '@/api/teachers'
  export default {
    name: 'Teacher',
    data() {
      return {
        formItem: {
          id: '',
          name: '',
          password: '',
          code: '',
          email: '',
          phone: '',
          avatar: '',
          sid: ''
        }
      }
    },
    mounted() {
      this.queryList();
    },
    methods: {
      queryList: function () {
        getCurrentTeacher().then(res => {
          const {id, name, code, email, phone, avatar,sid} = res.data;
          this.formItem = {
            id, name, code, email, phone, avatar,sid,
            password:''
          };
        });
      },
      handleBeforeUpload() {
      },

      btnSaveClick: function () {
        updateTeacher(this.formItem.id, this.formItem).then(res => {
          if (res.data && res.data.affectedRows > 0) {
            this.$Message.success('保存成功!');
            this.queryList();
          } else {
            this.$Message.error(res.error);
          }
        });
      },
    }
  }

</script>
